import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;

public class EsmTest {

    /**
     * 通过HttpURLConnection模拟post表单提交
     * @throws Exception
     */
  
	public static void main(String[] args)throws Exception{
		sendEms();
		
	}
	
	
    public static void sendEms() throws Exception {

    	Properties systemProperties = System.getProperties();
		systemProperties.setProperty("http.proxyHost","wwwgate0-ch.mot.com");
		systemProperties.setProperty("http.proxyPort","1080");

        String wen = "EQ353574035CS";
        String btnSearch = "EMS快递查询";
        URL url = new URL("http://www.kd185.com/ems.php");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    	conn.addRequestProperty("Accept", "*/*");
		conn.addRequestProperty("Accept-Language", "zh-cn");
        conn.setRequestMethod("POST");// 提交模式
        // conn.setConnectTimeout(10000);//连接超时 单位毫秒
        // conn.setReadTimeout(2000);//读取超时 单位毫秒
        conn.setDoOutput(true);// 是否输入参数

        
        String username="wen="+wen+"&btnSearch="+btnSearch;
      OutputStream ops=  conn.getOutputStream();
      ops.write(username.getBytes());
      ops.flush();
      ops.close(); 
        
       
      int code = conn.getResponseCode();
        System.out.println("code   " + code);
           
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"gbk"));
        String line;
        System.out.println("=============================");
        System.out.println("Contents of post request");
        System.out.println("=============================");
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        System.out.println("=============================");
        System.out.println("Contents of post request ends");
        System.out.println("=============================");
        reader.close();
        conn.disconnect();  
        

    }

}